//
//  DiscoverViewController.m
//  NewWeiBo_OC
//
//  Created by 陈竹 on 16/2/21.
//  Copyright © 2016年 陈竹. All rights reserved.
//

#import "DiscoverViewController.h"
#define DiscoverCellID @"DiscoverCellID"
@interface DiscoverViewController ()
@property(nonatomic,strong)NSMutableArray *DdataList;
@end

@implementation DiscoverViewController
#pragma mark - 懒加载
-(NSMutableArray *)DdataList{
    if (_DdataList==nil) {
        _DdataList=[NSMutableArray array];
        [_DdataList addObject:@"b"];
    }
    return _DdataList;
}

#pragma mark - 其他
- (void)viewDidLoad {
    [self setupRefresh];
    [super viewDidLoad];
    //注册可重用id Cell
    UITableViewCell *cell=[[UITableViewCell alloc]init];
    [self.tabelView registerClass:[cell class] forCellReuseIdentifier:DiscoverCellID];
    
}

-(void)loadData{
    NSLog(@"ss");
    
    BOOL isPullUp=self.pullUpView.isAnimating;
    if (!isPullUp) {
        [self.refresh beginRefreshing];
    }

    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [NSThread sleepForTimeInterval:2];
        NSMutableArray *arrayM=[NSMutableArray array];
        for (int i=0; i<10; i++) {
            NSString *str=[NSString stringWithFormat:@"%d+%@",i,self.DdataList.lastObject];
            [arrayM addObject:str];
        }
        
     
        [self.DdataList addObjectsFromArray:arrayM];
        NSLog(@"%ld",self.DdataList.count);
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tabelView reloadData];
            [self.pullUpView stopAnimating];
            [self.refresh endRefreshing];
        });
    });
}

#pragma mark - 数据源和代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"%ld",self.DdataList.count);
    return self.DdataList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:DiscoverCellID forIndexPath:indexPath];
    cell.textLabel.text=self.DdataList[indexPath.row];
    return cell;

}

@end
